/*
 * $Id: CalendarConverter.java 30 2006-06-08 13:26:40Z wjx $
 */
package	com.someok.utils.datetime.converters;

import java.util.Calendar;

import com.someok.utils.datetime.DateTimeStamp;
import com.someok.utils.datetime.JDateTime;

/**
 *
 * <p><a href="CalendarConverter.java.html"><i>View Source</i></a></p>
 *
 * @version $Revision: 30 $ $Date: 2006-06-08 21:26:40 +0800 (星期四, 08 六月 2006) $
 */
public class CalendarConverter implements com.someok.utils.datetime.JdtConverter {

	public void load(JDateTime gt, Object o) {
		if (o instanceof Calendar) {
			Calendar c = (Calendar) o;
			gt.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH) + 1, c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), c.get(Calendar.SECOND) + (double) c.get(Calendar.MILLISECOND) / 1000);
		}
	}

	public Object get(JDateTime gt) {
		Calendar c = Calendar.getInstance();
		store(gt, c);
		return c;
	}

	public void store(JDateTime gt, Object o) {
		if (o instanceof Calendar) {
			Calendar c = (Calendar) o;
			DateTimeStamp time = gt.getDateTimeStamp();
			c.set(time.year, time.month - 1, time.day, time.hour, time.minute, (int)time.second);
			c.set(Calendar.MILLISECOND, (int) ((time.second - (int)time.second) * 1000));
		}
	}

}
